package com.treasury.glasses.domain;

import com.treasury.glasses.domain.fields.ActivityType;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Entity for logging the ProgramUser's activity.
 * @author <a href="mailto:glasses@audienz.eu">Jean-Luc Burot</a>
 */

@Entity
@NamedQueries({
    @NamedQuery(name = ActivityLog.ACTIVITIES_OF_USER, query = "SELECT al FROM ActivityLog al WHERE al.programUser = :programUser ORDER BY al.creation DESC")
})
public class ActivityLog implements Serializable {
    private static final long serialVersionUID = 1L;
    
    /**
     * Prefix for the NamedQuery name.
     */
    private static final String PREFIX = "ActivityLog.";
    
    /**
     * Name to identify the desired NamedQuery in service classes.
     */
    public static final String ACTIVITIES_OF_USER = PREFIX + "activitiesOfUser";
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false, updatable = false)
    private Date creation;
    
    @Enumerated(EnumType.STRING)
    @Column(nullable = false, updatable = false)
    private ActivityType activityType;
    
    @ManyToOne
    private ProgramUser programUser;
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    
    public Date getCreation() {
        return creation;
    }
    
    public void setCreation(Date creation) {
        this.creation = creation;
    }
    
    public ActivityType getActivityType() {
        return activityType;
    }
    
    public void setActivityType(ActivityType activityType) {
        this.activityType = activityType;
    }
    
    public ProgramUser getProgramUser() {
        return programUser;
    }
    
    public void setProgramUser(ProgramUser programUser) {
        this.programUser = programUser;
    }
}
